package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Task;
import cn.wolfcode.crm.domain.TaskExecute;
import cn.wolfcode.crm.query.impl.TaskExecuteQuery;
import cn.wolfcode.crm.service.IAttendanceService;
import cn.wolfcode.crm.service.ITaskExecuteService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("taskExecute")
public class TaskExecuteController {
    @Autowired
    private ITaskExecuteService service;
    @RequiresPermissions(value = {"taskExecute:view","任务页面"},logical= Logical.OR)
    @RequestMapping("view")
    public String view() {
        return "taskExecute";
    }
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(TaskExecuteQuery qo){
        return service.query(qo);
    }
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Task task,Long employeeId,Long tid){
        try {
            service.saveOrUpdate(task,employeeId,tid);
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"编辑失败");
        }
        return new JSONResult();
    }
    @RequestMapping("editstate")
    @ResponseBody
    public JSONResult editstate(Long tid){
        try {
            service.updatestate(tid);
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"操作失败");
        }
        return new JSONResult();
    }
    @RequestMapping("exportXls")
    public void exportXls(HttpServletResponse response) throws IOException {
        service.exportXls(response);

    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult taskdelete(Long tid){
        try {
            service.deleteByTid(tid);
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult(false,"操作失败");
        }
        return new JSONResult();
    }

}
